package com.hafu.view;
import com.hafu.model.KuCun;
import com.hafu.service.KuCunService;
import java.awt.*;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.*;
import javax.swing.GroupLayout;
import javax.swing.table.*;
public class KuCunFrm extends JFrame {
    private final KuCunService kuCunService= new KuCunService();
    public KuCunFrm() {
        initComponents();
        fillTableData();
    }
    private void fillTableData() {
        DefaultTableModel model = (DefaultTableModel) table1.getModel();
        model.setRowCount(0);
        ArrayList<KuCun> list=kuCunService.getKuCunList();
        for (KuCun kuCun : list) {
            Vector<Object> rowData = new Vector<>();
            rowData.add(kuCun.getId());
            rowData.add(kuCun.getSpname());
            rowData.add(kuCun.getNum());
            model.addRow(rowData);
        }
    }
    private void initComponents() {
        JScrollPane scrollPane1 = new JScrollPane();
        table1 = new JTable();
        setTitle("\u5e93\u5b58\u8be6\u5355");
        Container contentPane = getContentPane();
        {
            table1.setModel(new DefaultTableModel(
                    new Object[][] {
                            {null, null, null},
                            {null, null, null},
                    },
                    new String[] {
                            "\u7f16\u53f7", "\u540d\u79f0", "\u6570\u91cf"
                    }
            ));
            scrollPane1.setViewportView(table1);
        }
        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 667, GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(119, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                                .addContainerGap(33, Short.MAX_VALUE)
                                .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                .addGap(23, 23, 23))
        );
        pack();
        setLocationRelativeTo(getOwner());
    }

    private JTable table1;
}